﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Control;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NLBS.Data;
using NLBS.Web;
using NLBS.Web.UI;
namespace NLBS
{
    public class MessageHelp
    {
        public static void ShowArticleAction(System.Web.UI.Control content)
        {

            if (!String.IsNullOrEmpty(RequestWrapper.GetQueryString("act")))
            {
                string act = RequestWrapper.GetQueryString("act").ToString();
                string siteurl = string.Empty;
                if (String.IsNullOrEmpty(RequestWrapper.GetQueryString("id")))
                {
                    siteurl = ReWriteUrls.Instance().ArticleConent(RequestWrapper.GetQueryInt("id"));
                }
                switch (act)
                {
                    case "save":
                        content.Controls.Clear();
                        content.Controls.Add(new MessageBox(NLBS.Web.UI.MessageType.Success, 
                            "新增文章成功", "完成", "[点击立即返回]", "/default.aspx", true));
                        break;
                    case "update":
                        content.Controls.Clear();
                        content.Controls.Add(new MessageBox(NLBS.Web.UI.MessageType.Success, 
                            "更新文章成功", "完成", "[点击立即返回]", "/default.aspx", true));
                        break;
                    case "delete":
                        content.Controls.Clear();
                        content.Controls.Add(new MessageBox(NLBS.Web.UI.MessageType.Success, 
                            "删除文章成功", "完成", "[点击立即返回]", "/default.aspx", true));
                        break;
                }
             
            }
        }

        public static void ShowCommentAction(Page page, System.Web.UI.Control comment)
        {
            if (HttpContext.Current.Request.QueryString["act"] != null)
            {
                message msg = (message)page.LoadControl("~/Control/message.ascx");
                string act = HttpContext.Current.Request.QueryString["act"].ToString();
                string siteurl = string.Empty;
                if (HttpContext.Current.Request.QueryString["logid"] != null)
                {
                    siteurl=ReWriteUrls.Instance().ArticleConent(Convert.ToInt32(HttpContext.Current.Request.QueryString["logid"]));
                }
                if (act == "edit")
                {
                    comment.Visible = false;
                    page.Master.FindControl("mainWrapper").Visible = true;
                    page.Master.FindControl("mainWrapper").Controls.Clear();
                }
                if (act == "save")
                {
                    msg.SuccessContent = "新增评论成功";
                    msg.NextUrl = siteurl;
                    page.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
                else if (act == "update")
                {
                    msg.SuccessContent = "更新评论成功";
                    msg.NextUrl = siteurl;
                    page.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
                else if (act == "delete")
                {
                    msg.SuccessContent = "删除评论成功";
                    msg.NextUrl = siteurl;
                    page.Master.FindControl("mainWrapper").Controls.Add(msg);
                }
            }
        }

        public static void ShowGuestBookAction(Page page, System.Web.UI.Control guestbook)
        {
            if (HttpContext.Current.Request.QueryString["act"] != null)
            {
                message msg = (message)page.LoadControl("~/Control/message.ascx");
                string act = HttpContext.Current.Request.QueryString["act"].ToString();
                if (act != "edit" && act != "new")
                {
                    guestbook.Visible = false;
                    page.Master.FindControl("mainWrapper").Visible = true;
                    page.Master.FindControl("mainWrapper").Controls.Clear();
                }
                if (act == "edit")
                {
                    guestbook.Visible = false;
                    page.Master.FindControl("mainWrapper").Visible = true;
                    page.Master.FindControl("mainWrapper").Controls.Clear();
                }
                if (act == "save")
                {
                    msg.SuccessContent = "新增留言成功";
                }
                else if (act == "update")
                {
                    msg.SuccessContent = "更新留言成功";
                }
                else if (act == "delete")
                {
                    msg.SuccessContent = "删除留言成功";
                }
                if (act == "save" || act == "update" || act == "delete")
                {
                    msg.NextUrl = ReWriteUrls.Instance().GuestBook();
                    page.Master.FindControl("mainWrapper").Controls.Add(msg);
                }

            }
        }

        //public static void ShowUserAction(Page page, System.Web.UI.Control user);
    }
}
